<!--
 * @Author: liuyonghu liuyonghu.com
 * @Date: 2025-08-19 17:55:53
 * @LastEditors: liuyonghu liuyonghu.com
 * @LastEditTime: 2025-08-19 18:19:15
 * @FilePath: /demos/file/demo.html
-->
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <input type="file" name="" id="">
    <br />
    <button onclick="read()"> read</button>
    <script>
        const read = () => {
            const fileInput = document.querySelector('input[type="file"]');

            const fileReader = new FileReader();
            // fileReader.readAsText(fileInput.files[0]);
            fileReader.readAsDataURL(fileInput.files[0]);
            fileReader.onload = function (e) {
                console.log(e.target.result);
                const text = e.target.result.split(',')[1]; // Extract base64 part
                const blob = new Blob([text], { type: 'text/plain' });
                const url = URL.createObjectURL(blob);
                window.open(url, '__blank');
            };
        }

    </script>
</body>

</html>